package com.gladlee.myACP.tool;
import java.io.UnsupportedEncodingException;
public class myAtomTool {
	public static boolean isInStringArray(String[] sa, String s) {
		for (int i = 0; i < sa.length; i++) {
			if (s.equalsIgnoreCase(sa[i])) {
				return true;
			}
		}
		return false;
	}

	public static int getInt(byte b) {
		return b >= 0 ? b : b + 256;
	}

	public static long getLong(byte b) {
		return b >= 0 ? b : b + 256;
	}

	public static int getInt(byte[] bs) {
		int num = 0;
		for (int i = 0; i < 4; i++) {
			num += getInt(bs[i]) << (i * 8);
		}
		return num;
	}

	public static String getString(byte[] bs) {
		return new String(bs, 0, bs.length);
	}

	public static byte[] getBytes(long num) {
		byte[] bytes = new byte[8];
		for (int i = 0; i < 8; i++) {
			bytes[i] = (byte) ((num >> (i * 8)) & 0xff);
		}
		return bytes;
	}

	public static byte[] getBytes(double num) {
		long l = Double.doubleToLongBits(num);
		return getBytes(l);
	}

	public static byte[] getBytes(int num) {
		byte[] bytes = new byte[4];
		for (int i = 0; i < 4; i++) {
			bytes[i] = (byte) ((num >> (i * 8)) & 0xff);
		}
		return bytes;
	}

	public static byte[] getBytes(String s) throws UnsupportedEncodingException {
		return s.getBytes("UTF-8");
	}

	public static long getLong(byte[] bytes) {
		long num = 0;
		for (int i = 0; i < 8; i++) {
			num += getLong(bytes[i]) << (i * 8);
		}
		return num;
	}

	public static double getDouble(long num) {
		return Double.longBitsToDouble(num);
	}

	public static double getDouble(byte[] bytes) {
		return getDouble(getLong(bytes));
	}
}
